﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using Model;

public partial class ReadBaoMing : System.Web.UI.PageEx
{
    private DataSet ds = null;
    public static string strId = "0";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            string strResult = string.Empty;
            if (!DalEx.DbUserDalEx.CheckUserLogin(UserType, UserId, ref strResult))
            {
                MessageBox(strResult, "UserLogin.aspx");
                return;
            }
            string strLink = "<li><a href=\"{0}\" class=\"{2}\">{1}</a></li>";
            StringBuilder sbMenuLinks = new StringBuilder();
            if (UserType == 1 && UserId > 0)
            {
                sbMenuLinks.Append(string.Format(strLink, new object[] { "MemberCenter.aspx", "会员中心", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "UserInfos.aspx", "我的资料", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "ModifyPwd.aspx", "修改密码", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "MyBaoMing.aspx", "我的报名表", "on" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "MyYiGongBaoMing.aspx", "义工报名表", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "MyHomeEventBaoMing.aspx", "家园活动报名表", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "Logout.aspx", "退出系统", "" }));
            }
            else
            {
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "会员中心", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "我的资料", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "修改密码", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "我的报名表", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "义工报名表", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "家园活动报名表", "" }));
                sbMenuLinks.Append(string.Format(strLink, new object[] { "#", "退出系统", "" }));
            }
            litMenuLinks.Text = sbMenuLinks.ToString();

            DataBinds();
        }

    }

    private void DataBinds()
    {
        if (!string.IsNullOrEmpty(Request.QueryString["Id"]))
        {
            strId = Request.QueryString["Id"].ToString();
        }
        int iUserId = 0;
        int.TryParse(strId, out iUserId);
        Model.BaoMing M_BaoMing = Dal.BaoMingDal.Select(iUserId);
        if (M_BaoMing != null)
        {
            lblUserName.Text = M_BaoMing.UserName;
            lblSex.Text = GetSex(M_BaoMing.Sex);
            lblBirthday.Text = M_BaoMing.Birthday.ToString("yyyy-MM-dd");
            lblPlaceOrigin.Text = M_BaoMing.PlaceOrigin;
            lblPlaceBirth.Text = M_BaoMing.PlaceBirth;
            lblClass.Text = GetClassType(M_BaoMing.RegClass);
            lblIdCardNo.Text = M_BaoMing.IdCardNo;
            lblCensusClass.Text = GetCensusClass(M_BaoMing.CensusClass);
            lblCensusAddr.Text = M_BaoMing.CensusAddr;
            lblIsInSchool.Text = GetTrueFalse(M_BaoMing.IfInSchool);
            lblHadInSchool.Text = M_BaoMing.InSchoolInfo;
            lblAllergicHistory.Text = M_BaoMing.AllergicHistory;
            lblSepcialDisease.Text = M_BaoMing.SepcialDisease;
            lblFatherName.Text = M_BaoMing.FatherName;
            lblFatherWorks.Text = M_BaoMing.FatherWorks;
            lblFatherTel.Text = M_BaoMing.FatherTel;
            lblFatherInSZ.Text = GetTrueFalse(M_BaoMing.FatherInSZ);
            lblFatherPaySB.Text = GetTrueFalse(M_BaoMing.FatherPaySB);
            lblFatherPayJZZ.Text = GetTrueFalse(M_BaoMing.FatherPayJZZ);
            lblMotherName.Text = M_BaoMing.MotherName;
            lblMotherWorks.Text = M_BaoMing.MotherWorks;
            lblMotherTel.Text = M_BaoMing.MotherTel;
            lblMotherInSZ.Text = GetTrueFalse(M_BaoMing.MotherInSZ);
            lblMotherPaySB.Text = GetTrueFalse(M_BaoMing.MotherPaySB);
            lblMotherPayJZZ.Text = GetTrueFalse(M_BaoMing.MotherPayJZZ);
            lblNoteNo.Text = M_BaoMing.NoteNo;
            string houseAddr = M_BaoMing.HouseAddr;
            if (M_BaoMing.HouseNature == 1 && M_BaoMing.HouseRegionID>0) {
                houseAddr = "深圳市龙岗区";
                if (M_BaoMing.HouseRegionID > 0)
                {
                    DbHouseRegion hr = Dal.DbHouseRegionDal.Select(M_BaoMing.HouseRegionID);
                    houseAddr += hr.HouseRegionName;
                }
                if (M_BaoMing.HouseGroupID > 0)
                {
                    DbHouseGroup hg = Dal.DbHouseGroupDal.Select(M_BaoMing.HouseGroupID);
                    houseAddr += hg.HouseGroupName;
                }
                if (M_BaoMing.HouseNumberID > 0)
                {
                    DbHouseNumber hn = Dal.DbHouseNumberDal.Select(M_BaoMing.HouseNumberID);
                    houseAddr += hn.HouseNumberName;
                }
                if (M_BaoMing.HouseNumber1 > 0)
                {
                    DbHouseNumber hn = Dal.DbHouseNumberDal.Select(M_BaoMing.HouseNumber1);
                    houseAddr += hn.HouseNumberName;
                }
                if (M_BaoMing.HouseNumber2 > 0)
                {
                    DbHouseNumber hn = Dal.DbHouseNumberDal.Select(M_BaoMing.HouseNumber2);
                    houseAddr += hn.HouseNumberName;
                }
                if (M_BaoMing.HouseNumberID > 0)
                {
                    houseAddr += "室";
                }
            }
            if (M_BaoMing.HouseNature == 5) {
                lblNoteLable.Visible = false;
                lblNoteNo.Visible = false;
                lblBuyLable.Visible = false;
            }
            lblHouseAddr.Text = houseAddr;
            lblHouseNature.Text = GetHouseNature(M_BaoMing.HouseNature);

            lblBuyHouseDate.Text = M_BaoMing.HouseNature == 1 ? M_BaoMing.BuyHouseDate.ToString("yyyy-MM-dd") : string.Empty;

            lblPlanning.Text = GetPlanning(M_BaoMing.Planning);
            //lblChildCounts.Text = M_BaoMing.ChildCounts.ToString();
            //lblChildIndex.Text = M_BaoMing.ChildIndex.ToString();
            //lblCaseType.Text = GetCaseType(M_BaoMing.CaseType);
            lblNotes.Text = M_BaoMing.Notes;
            lblSignName.Text = M_BaoMing.SignName;
            lblSignDate.Text = M_BaoMing.SignDate.ToString("yyyy年MM月dd日");

            lblFatherCardNo.Text = M_BaoMing.FatherCardNo;
            lblMotherCardNo.Text = M_BaoMing.MotherCardNo;
            lblNurserySchool.Text = GetNurserySchool(M_BaoMing.NurserySchool);
        }
    }
    public int ReadStringToInt(string str)
    {
        if (string.IsNullOrEmpty(str))
        {
            str = "0";
        }
        return Convert.ToInt32(str);
    }

    public DateTime ReadStringToDate(string str)
    {
        if (string.IsNullOrEmpty(str))
        {
            str = DateTime.Now.ToString("yyyy-MM-dd");
        }
        return Convert.ToDateTime(str);
    }

    public decimal ReadStringToDecimal(string str)
    {
        if (string.IsNullOrEmpty(str))
        {
            str = "0";
        }
        return Convert.ToDecimal(str);
    }
    #region 属性转化
    protected string GetSex(object objValue)
    {
        int iValue = Convert.ToInt32(objValue);
        return iValue == 1 ? "男" : "女";
    }
    protected string GetTrueFalse(object objValue)
    {
        int iValue = Convert.ToInt32(objValue);
        return iValue == 1 ? "是" : "否";
    }
    protected string GetStatus(object objValue)
    {
        string strResult = string.Empty;
        int iValue = Convert.ToInt32(objValue);
        switch (iValue)
        {
            case 0:
                strResult = "未处理";
                break;
            case 1:
                strResult = "已查看";
                break;
            case 2:
                strResult = "已录取";
                break;
            case 3:
                strResult = "未录取";
                break;
        }
        return strResult;
    }
    protected string GetClassType(object objValue)
    {
        string strResult = string.Empty;
        int iValue = Convert.ToInt32(objValue);
        switch (iValue)
        {
            case 0:
                strResult = "小班";
                break;
            case 1:
                strResult = "中班";
                break;
            case 2:
                strResult = "大班";
                break;
            case 3:
                strResult = "大大班";
                break;
        }
        return strResult;
    }
    protected string GetCensusClass(object objValue)
    {
        string strResult = string.Empty;
        int iValue = Convert.ToInt32(objValue);
        switch (iValue)
        {
            //case 0:
            //    strResult = "龙岗";
            //    break;
            case 1:
                strResult = "深户";
                break;
            case 2:
                strResult = "非深户";
                break;
            case 3:
                strResult = "港籍";
                break;
            case 4:
                strResult = "台籍";
                break;
            case 5:
                strResult = "澳籍";
                break;
            //case 6:
            //    strResult = "外籍";
                //break;
        }
        return strResult;
    }
    protected string GetHouseNature(object objValue)
    {
        string strResult = string.Empty;
        int iValue = Convert.ToInt32(objValue);
        switch (iValue)
        {
            case 0:
                strResult = "自建房";
                break;
            case 1:
                strResult = "购房";
                break;
            case 2:
                strResult = "租房";
                break;
            case 3:
                strResult = "单位房";
                break;
            case 4:
                strResult = "亲友房";
                break;
            case 5:
                strResult = "其他";
                break;
        }
        return strResult;
    }
    protected string GetPlanning(object objValue)
    {
        string strResult = string.Empty;
        int iValue = Convert.ToInt32(objValue);
        switch (iValue)
        {
            case 0:
                strResult = "独生子女";
                break;
            case 1:
                strResult = "非独生子女";
                break;
            case 2:
                strResult = "超生但办理罚款手续";
                break;
            case 3:
                strResult = "超生未办理罚款手续";
                break;
            case 4 :
                strResult = "政策内二孩";
                break;
            case 5: 
                strResult = "政策外但已接受处理的幼儿";
                break;
        }
        return strResult;
    }
    protected string GetCaseType(object objValue)
    {
        string strResult = string.Empty;
        int iValue = 0;
        foreach (string strValue in Convert.ToString(objValue).Split(','))
        {
            int.TryParse(strValue, out iValue);
            switch (iValue)
            {
                case 0:
                    strResult += "住得近、";
                    break;
                case 1:
                    strResult += "收费合理、";
                    break;
                case 2:
                    strResult += "办学质量好、";
                    break;
                case 3:
                    strResult += "环境好、";
                    break;
                case 4:
                    strResult += "师资好、";
                    break;
                case 5:
                    strResult += "家长口碑好、";
                    break;
                case 6:
                    strResult += "社会口碑好、";
                    break;
                case 7:
                    strResult += "别无选择、";
                    break;
            }
        }
        return strResult.EndsWith("、") ? strResult.Substring(0, strResult.Length - 1) : strResult;
    }
    protected string GetNurserySchool(object objValue)
    {
        string strResult = string.Empty;
        int iValue = Convert.ToInt32(objValue);
        switch (iValue)
        {
            case 0:
                strResult = "龙岗区机关幼儿园本部";
                break;
            case 1:
                strResult = "龙岗区机关幼儿园龙城分园";
                break;
            case 2:
                strResult = "龙岗区机关幼儿园南湾分园";
                break;
            case 3:
                strResult = "龙岗区机关幼儿园坂田分园";
                break;
        }
        return strResult;
    }
    #endregion
}
